﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.WS.UserControls;
using GCELibrary.Current;
using System.Transactions;
using ZF.BLL;
using Newtonsoft.Json;
using ZF.BLL.Admin;
namespace ZF.WS.Admin
{

    public partial class ExpertApplyManage : ExpertApply 
    {
    

        [PageArgument(Key = "id", CanNull = false, BindOperType = PageOperType.Edit)]
        public int  Id { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
               
                    Edit();
            }
        }
        public void InitControls()
        {

            this.ddlType.DataSource = BLL.DictionaryConfig.EExpertType;
            this.ddlType.DataBind();
     
        }

        public void Add()
        {
            InitControls();

        }
        public void AddSubmit(object sender, EventArgs e)
        {

             

        }
      
        public void Edit()
        {
            using (var dc = BLL.SiteInfo.CreateDBDataContext())
            {
                var ea = dc.E_ExpertApply.FirstOrDefault(p => p.ExpertApplyId == Id);
                if (ea == null)
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                var member = ea.US_Member;
                if (member == null)
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                InitControls();
                this.tbAccount.Text = member.Account;
                this.tbReason.Text = ea.Content;
                this.tbAbout.Text = member.About;
                this.tbSpecialty.Text = member.Specialty;
                this.MemberInfo1.Member = member;
            }
        }
        public void EditSubmit(object sender, EventArgs e)
        {

            using (var ts = new System.Transactions.TransactionScope())
            {
                using (var dc = BLL.SiteInfo.CreateDBDataContext())
                {
                    var ea = dc.E_ExpertApply.FirstOrDefault(p => p.ExpertApplyId == Id);
                    if (ea == null)
                        throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                    var member = ea.US_Member;
                    if (member == null)
                        throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                    var arg = ((IButtonControl)sender).CommandArgument;
                    if (arg.EqIgnoreCase("success"))
                    {
                        ea.Status = 1;
                        member.IsExpert = true;
                    }
                    else if (arg.EqIgnoreCase("fail"))
                    {
                        ea.Status = -1;
                        member.IsExpert = false;
                    }
                    try
                    { 
                        dc.SubmitChanges();
                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        throw WarnFactory.CreateWarn(ex);
                    }
                    
                    string msgKey = "";
                    
                    WarnFactory.CreateWarn(new PageWarnParameter()
                    {
                         JscriptMode=true,
                          Message="操作成功",
                           Link= WarnLink.GoBack,
                    }).Alert();
                   
      
                }


            }

        }

    
    }
 
}
